Public Class frmTraCuuNha

    Private Sub frmTraCuuNha_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim listNha As New DataTable()
        listNha = NhaBUS.GetAll()
        gvDSNha.DataSource = listNha

        Dim listLoaiNha As New List(Of LoaiNhaDTO)
        listLoaiNha = LoaiNhaBUS.GetAll()
        cbxTimLoaiNha.DataSource = listLoaiNha
        cbxTimLoaiNha.ValueMember = "iMaLoaiNha"
        cbxTimLoaiNha.DisplayMember = "strTenLoaiNha"

        Dim listQuan As New List(Of QuanDTO)
        listQuan = QuanBUS.GetAll()
        cbxTimQuan.DataSource = listQuan
        cbxTimQuan.ValueMember = "iMaQuan"
        cbxTimQuan.DisplayMember = "strTenQuan"
    End Sub
    Private Sub cbxLuaChon_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxLuaChon.SelectedIndexChanged
        Dim luachon As Integer = cbxLuaChon.SelectedIndex

        Select Case luachon
            Case 0
                lbQuan.Enabled = True
                cbxTimQuan.Enabled = True

                lbLoaiNha.Enabled = False
                cbxTimLoaiNha.Enabled = False

                lbTinhTrang.Enabled = False
                rbtTimDaThue.Enabled = False
                rbtTimChuaThue.Enabled = False
            Case 1
                lbLoaiNha.Enabled = True
                cbxTimLoaiNha.Enabled = True

                lbQuan.Enabled = False
                cbxTimQuan.Enabled = False

                lbTinhTrang.Enabled = False
                rbtTimDaThue.Enabled = False
                rbtTimChuaThue.Enabled = False
            Case 2
                lbTinhTrang.Enabled = True
                rbtTimDaThue.Enabled = True
                rbtTimChuaThue.Enabled = True

                lbQuan.Enabled = False
                cbxTimQuan.Enabled = False

                lbLoaiNha.Enabled = False
                cbxTimLoaiNha.Enabled = False
        End Select

    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        Dim luachon As Integer = cbxLuaChon.SelectedIndex

        Select Case luachon
            Case 0
                Dim listNha As New DataTable()
                listNha = NhaBUS.TimKiemNhaTheoQuan(cbxTimQuan.SelectedValue)
                gvDSNha.DataSource = listNha
            Case 1
                Dim listNha As New DataTable()
                listNha = NhaBUS.TimKiemNhaTheoLoaiNha(cbxTimLoaiNha.SelectedValue)
                gvDSNha.DataSource = listNha
            Case 2
                Dim listNha As New DataTable()
                Dim tinhtrang As Boolean
                If rbtTimDaThue.Checked = True Then
                    tinhtrang = True
                ElseIf rbtTimChuaThue.Checked = True Then
                    tinhtrang = False
                End If

                listNha = NhaBUS.TimKiemNhaTheoTinhTrang(tinhtrang)
                gvDSNha.DataSource = listNha

        End Select

    End Sub

    Private Sub btnTatCa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTatCa.Click
        Dim listNha As New DataTable()
        listNha = NhaBUS.GetAll()
        gvDSNha.DataSource = listNha
    End Sub

    Private Sub gvDSNha_CellFormatting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles gvDSNha.CellFormatting
        If (gvDSNha.Columns(e.ColumnIndex).Name = "gia") Then
            e.CellStyle.Format = "#,##"
        End If
    End Sub
End Class